package leetcode_core.leetcode_3;

public class TwoSum {
    public int[] twoSum(int[] numbers, int target) {
        int left = 0, right = numbers.length - 1;
        while (left <= right) {//定义搜索区间l<=r
            int cur = numbers[left] + numbers[right];
            if (cur == target) {
                break;
            } else if (cur < target) {
                left++;
            } else if (cur > target) {
                right--;
            }
        }
        int[] ans = new int[2];
        ans[0] = numbers[left] ;
        ans[1] = numbers[right] ;
        return ans;
    }
}
